import request from '@/utils/request'
// spu.js
// 查询商品SPU列表
export function listSpuVo(query) {
  return request({
    url: '/transaction/spu/list',
    method: 'get',
    params: query
  })
}

// 查询商品SPU详细
export function getSpu(id) {
  return request({
    url: '/transaction/spu/' + id,
    method: 'get'
  })
}

// 新增商品SPU
export function addSpu(data) {
  return request({
    url: '/transaction/spu',
    method: 'post',
    data: data
  })
}

// 修改商品SPU
export function updateSpu(data) {
  return request({
    url: '/transaction/spu',
    method: 'put',
    data: data
  })
}

// 删除商品SPU
export function delSpu(id) {
  return request({
    url: '/transaction/spu/' + id,
    method: 'delete'
  })
}
// 获得商品SPU所拥有的规格及其值
export function getAllSpuWithSpecs() {
  return request({
    url: 'transaction/spu/SpuWithSpecs',
    method: 'get' 
  })
}

//  向spu和规格的关联表中插入数据
// 向spu和规格的关联表中插入数据
export function addSpuSpec(spuId, specId) {
  return request({
    url: 'transaction/spu/addSpuSpec',
    method: 'post',
    params: {
      spuId: spuId,
      specId: specId
    }
  })
}

// 获取SPU已关联的规格ID列表
export function getSpuSpecs(spuId) {
  return request({
    url: `/transaction/spu/${spuId}/specs`,
    method: 'get'
  })
}